package com.it.service;

import com.it.mapper.ClOrderMapper;
import com.it.pojo.ClOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClOrderServiceImpl implements ClOrderService {

	//由spring创建对象并为变量赋值
	@Autowired
	private ClOrderMapper clOrderMapper;

	/**
	 * 1.查询所有订单信息
	 * @return
	 */
	public List<ClOrder> findAll(){
		//1.调用orderMapper的findAll方法查询所有订单
		List<ClOrder> list = clOrderMapper.findAll();
		return list;
	}
	
	/**
	 * 2.根据id删除订单信息
	 * @param id
	 */
	public int deleteById(String id){
		//1.调用OrderMapper的deleteById方法
		//根据id删除订单信息
		int result = clOrderMapper.deleteById(id);
		return result;
	}
	
	/**
	 * 3.添加订单信息
	 * @param order
	 */
	public int addClOrder(ClOrder order){
		int result = clOrderMapper.addClOrder(order);
		return result;
	}

	/**
	 * 4.1.根据id查询订单信息
	 * @param id
	 * @return
	 */
	public ClOrder findById(String id){
		ClOrder order = clOrderMapper.findById(id);
		return order;
	}

	/**
	 * 4.2.根据用户和购物车查询订单信息
	 * @param userId
	 * @param cartId
	 * @return
	 */
	public List<ClOrder> findByUserIdAndCartId(String userId, String cartId){
		List<ClOrder> list = clOrderMapper.findByUserIdAndCartId(userId, cartId);
		return list;
	}
	
	/**
	 * 5.根据id修改订单信息
	 * @param order
	 */
	public int updateById(ClOrder order){
		int result = clOrderMapper.updateById(order);
		return result;
	}
	
}
